// 五行生克规则
const fiveElementsRules = {
    "金": { "生": "水", "克": "木" },
    "木": { "生": "火", "克": "土" },
    "水": { "生": "木", "克": "火" },
    "火": { "生": "土", "克": "金" },
    "土": { "生": "金", "克": "水" }
};

// 获取选择按钮和结果显示区域
const choiceButtons = document.querySelectorAll('#choices button');
const resultDiv = document.getElementById('result');

// 为每个按钮添加点击事件监听器
choiceButtons.forEach(button => {
    button.addEventListener('click', function () {
        const userChoice = this.dataset.element;
        const computerChoices = ["金", "木", "水", "火", "土"];
        const computerChoice = computerChoices[Math.floor(Math.random() * computerChoices.length)];

        let outcome;
        if (userChoice === computerChoice) {
            outcome = "平局！你和电脑都选择了 " + userChoice;
        } else if (fiveElementsRules[userChoice].克 === computerChoice) {
            outcome = "你赢了！你的 " + userChoice + " 克电脑的 " + computerChoice;
        } else {
            outcome = "你输了！电脑的 " + computerChoice + " 克你的 " + userChoice;
        }

        resultDiv.innerHTML = `<p>你选择了 ${userChoice}，电脑选择了 ${computerChoice}。</p><p>${outcome}</p>`;
    });
});